import React, { useReducer } from 'react';

// Reducer 的简单使用
function Reducer() {
  const [count, dispatch] = useReducer((state, action) => {
    switch (action) {
      case 'add':
        return state + 1
      case "sub":
        return state - 1
      default:
        return state;
    }
  }, 0)
  return (
    <>
      <p>你点击了 {count} 次</p>
      <button onClick={() => dispatch('add')}>+</button> 
      <button onClick={() => dispatch('sub')}>-</button>
    </>
  )
}

export default Reducer
